package com.fly.web;

import com.fly.utils.DateUtils;
import org.springframework.beans.propertyeditors.PropertiesEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.util.Date;

/**
 * @author Fly
 * @Description 控制器支持类
 * @Date Created in 15:04 2017/11/9
 * @Modified by
 */
public abstract class BaseController {

    /**
     * 表单提交时间String转Date
     *
     * @param binder
     */
    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        binder.registerCustomEditor(Date.class,new PropertiesEditor(){
            @Override
            public void setAsText(String text) {
                setValue(DateUtils.parseDate(text));
            }
        });
    }
}
